home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / bibtex / c / bibext next >
Encoding:
Text File  |  1990-01-19  |  3.3 KB  |  177 lines

  1. /*
  2.  * Auxilliary routines for BibTeX in C.
  3.  *
  4.  * Tim Morgan 2/15/88
  5.  * Eduardo Krell 4/21/88
  6.  */
  7.  
  8. #include <stdio.h>
  9. #ifdef  BSD
  10. #include <string.h>
  11. #else
  12. #include <string.h>
  13. #endif
  14. #include "site.h"
  15.  
  16. #define TRUE 1
  17. #define FALSE 0
  18. #define filenamesize 1024
  19. extern char realnameoffile[];
  20. extern schar xord[], buffer[];
  21. extern char nameoffile[];
  22. char **gargv;
  23. int gargc;
  24.  
  25. static char input_path[filenamesize], bib_path[filenamesize];
  26.  
  27. FILE *openf(name, mode)
  28. char *name, *mode;
  29. {
  30.     FILE *result;
  31.  
  32.     result = fopen(name, mode);
  33.     if (result == NULL) {
  34.         perror(name);
  35.         exit(1);
  36.     }
  37.     return(result);
  38. }
  39.  
  40. int eoln(f)
  41. FILE *f;
  42. {
  43.     register int c;
  44.  
  45.     if (feof(f)) return(1);
  46.     c = getc(f);
  47.     if (c != EOF)
  48.         (void) ungetc(c, f);
  49.     return (c == '\n' || c == EOF);
  50. }
  51.  
  52. void lineread(f, size)
  53. FILE *f;
  54. int size;
  55. {
  56.     extern long last;
  57.     register int in;
  58.  
  59.     last = 0;
  60.     while (last < size && (in = getc(f)) != EOF && in != '\n') {
  61. #ifdef  NONASCII
  62.         buffer[last++] = xord[in];
  63. #else
  64.         buffer[last++] = in;
  65. #endif
  66.     }
  67.     while (in != EOF && in != '\n')     /* Skip past eoln if buffer full */
  68.         (void) getc(f);
  69. }
  70.  
  71. void setpaths()
  72. {
  73.     extern char *getenv(char *s);
  74.     char *p;
  75.  
  76.  
  77.     input_path[0] = '\0';
  78.     bib_path[0] = '\0';
  79.  
  80.     if ((p = getenv("TEXINPUTS")) != NULL)
  81.         (void) strcpy(input_path, p);
  82.     else
  83.         (void) strcpy(input_path, TEXINPUTS);
  84.     if ((p = getenv("BIBINPUTS")) != NULL)
  85.         (void) strcpy(bib_path, p);
  86.     else
  87.         (void) strcpy(bib_path, BIBINPUTS);
  88. }
  89.  
  90.  
  91. static void packrealnameoffile(cpp)
  92. char **cpp;
  93. {
  94.     register char *p, *realname;
  95.  
  96.     realname = realnameoffile;
  97.     if ((p = *cpp)) {
  98.         while ((*p != ',') && *p) {/* GTOAL : -> , */
  99.             *realname++ = *p++;
  100.             if (realname == &(realnameoffile[filenamesize-1]))
  101.                 break;
  102.         }
  103.         if (*p == '\0') *cpp = NULL;
  104.         else *cpp = p+1;
  105.         /*   *realname++ = '.';*/  /*GTOAL don't add seperator */
  106.     }
  107.     p = nameoffile;
  108.     while (*p != ' ') {
  109.         if (realname >= &(realnameoffile[filenamesize-1])) {
  110.             fprintf(stderr, "! Full file name is too long\n");
  111.             break;
  112.         }
  113.         *realname++ = *p++;
  114.     }
  115.     *realname = '\0';
  116. }
  117.  
  118. int ztestaccess(wam, filepath)
  119. int wam, filepath;
  120. {
  121.     char *path = NULL;
  122.     register int ok;
  123.     int f;
  124.  
  125.     if (filepath == 1)
  126.         path = input_path;
  127.     else if (filepath == 2)
  128.         path = bib_path;
  129. /*   Need absolute path test ... search for $ or : ???
  130.     if (nameoffile[0] == '/')
  131.         path = NULL;
  132. */
  133.     do {
  134.         packrealnameoffile(&path);
  135.         if (wam == 4)
  136. /*
  137.             if (access(realnameoffile, 4) == 0) ok = TRUE;
  138.             else ok = FALSE;
  139.  */         ok = TRUE;
  140.         else {
  141. /*
  142.             f = creat(realnameoffile, 0666);
  143.             if (f >= 0) ok = TRUE;
  144.             else ok = FALSE;
  145.             if (ok)
  146.                 (void) close(f);
  147.  */         ok = TRUE;
  148.         }
  149.     }
  150.     while (!ok && path != NULL);
  151.     return(ok);
  152. }
  153.  
  154. int
  155. getcmdline(buf, n)
  156. char *buf;
  157. int n;
  158. {
  159.         strncpy(buf, gargv[1], n);
  160.         return (strlen(buf));
  161. }
  162.  
  163. main(argc, argv)
  164. char *argv[];
  165. {
  166.     extern schar history;
  167.     extern void main_body();
  168.     int status;
  169.  
  170.     gargc = argc;
  171.     gargv = argv;
  172.     setpaths();
  173.     main_body();
  174.     status = (history != 0);
  175.     exit(status);
  176. }
  177.